package com.tianqu.tms.dao;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.tianqu.tms.core.exception.TmsDaoException;
import com.tianqu.tms.dto.DectCodesDto;

public class DectCodesDaoImp extends TmsDao implements DectCodesDao {

	public DectCodesDaoImp() throws TmsDaoException {
		super();
	}
	
	@Override
	public List findCodesList() throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		DectCodesDto dto = null;
		List codesList = new ArrayList();
		
		try {
			conn = super.getConnection();
			
			StringBuffer sql = new StringBuffer();
			sql.append("SELECT ");
			sql.append("ID        	,");
			sql.append("ITEMID    	,");
			sql.append("ITEMCODE  	,");
			sql.append("ITEMVALUE 	 ");
			sql.append("FROM ");
			sql.append(TmsTableNames.DECT_CODE);

			ps = conn.prepareStatement(sql.toString());
			
			// 执行sql
			rs = ps.executeQuery();

			while (rs.next()) {
				dto = new DectCodesDto();
				dto.setItemId(rs.getInt("ITEMID"));
				dto.setItemCode(rs.getString("ITEMCODE"));
				dto.setItemValue(rs.getString("ITEMVALUE"));

				codesList.add(dto);
			}
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
			
		} finally {
			super.close(rs,ps);
		}
		return codesList;
	}
}
